CREATE PROCEDURE [dbo].[autoComplete_get_users_emails]
    @searchPattern nvarchar(256) = null
AS
if(@searchPattern is not null)
BEGIN
    SELECT DISTINCT TOP(20) 
        [dbo].[Users].[UserId],
        [dbo].[Users].[Email]
    FROM [dbo].[Users] 
    WHERE [dbo].[Users].[Email] LIKE '%' + @searchPattern + '%'
END ELSE
BEGIN
     SELECT TOP(20) 
        [dbo].[Users].[UserId],
        [dbo].[Users].[Email]
    FROM [dbo].[Users] 
    ORDER BY [dbo].[Users].[Email]
END

RETURN 0
